package com.bi.dataDmTrans.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bi.dataDmTrans.entity.DataItem;
import com.bi.dataDmTrans.mapper.DataItemMapper;
import com.bi.dataDmTrans.service.DataItemService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Slf4j
public class DataItemServiceImpl extends ServiceImpl<DataItemMapper, DataItem> implements DataItemService {

    @Override
    @Transactional
    public void saveDataToDatabase(List<DataItem> data) {
        log.info("开始保存数据,数据量:{}", data.size());
        if (!data.isEmpty()) {
            try {
                log.info("开始插入数据");
                // 批量插入数据
                boolean result = this.saveBatch(data);
                if (result) {
                    log.info("数据插入完成");
                } else {
                    log.error("数据插入失败");
                }
            } catch (Exception e) {
                log.error("数据插入过程中发生错误", e);
            }
        } else {
            log.warn("数据为空，未执行插入操作");
        }
    }
}
